package com.leyou.page.service;

import com.leyou.item.pojo.*;
import com.leyou.page.client.BrandClient;
import com.leyou.page.client.CategoryClient;
import com.leyou.page.client.GoodsClient;
import com.leyou.page.client.SpecClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PageService {
    @Autowired
    private CategoryClient categoryClient;

    @Autowired
    private BrandClient brandClient;

    @Autowired
    private GoodsClient goodsClient;

    @Autowired
    private SpecClient specClient;

    public Map<String, Object> loadModel(Long spuId) {

        Map<String, Object> map = new HashMap<>();
        Spu spu = goodsClient.querySpuById(spuId);
        List<Category> categories = categoryClient.queryCategoryByIds(Arrays.asList(spu.getCid1(), spu.getCid2(), spu.getCid3()));
        SpuDetail detail = spu.getSpuDetail();
        Brand brand = brandClient.queryBrandById(spu.getBrandId());
        List<SpecGroup> groups = specClient.queryListByCid(spu.getCid3());
        map.put("categories", categories);
        map.put("brand",brand);
        map.put("spu", spu);
        map.put("spuDetail",detail);
        map.put("skus",spu.getSkus());
        map.put("groups",groups);
        return map;
    }
}
